﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeepSpace.Geometry
{
    public class BoundingBox
    {
        public Point MinPoint { get; set; }
        public Point MaxPoint { get; set; }

        public BoundingBox(BoundingBox other):
            this(other.MinPoint, other.MaxPoint)
        {
        }

        public BoundingBox(Point minPoint, Point maxPoint)
        {
            this.MinPoint = new Point(minPoint);
            this.MaxPoint = new Point(maxPoint);
        }

        public bool Intersects(BoundingBox other)
        {
            return MinPoint.X <= other.MinPoint.X && 
                   MaxPoint.X >= other.MaxPoint.X &&
                   MinPoint.Y <= other.MinPoint.Y && 
                   MaxPoint.Y >= other.MaxPoint.Y && 
                   MinPoint.Z <= other.MinPoint.Z && 
                   MaxPoint.Z >= other.MaxPoint.Z;
        }

        public bool Contains(Point point)
        {
            return MaxPoint.X >= point.X && 
                   MinPoint.X <= point.X &&
                   MaxPoint.Y >= point.Y && 
                   MinPoint.Y <= point.Y &&
                   MaxPoint.Z >= point.Z && 
                   MinPoint.Z <= point.Z;
        }

        public void Include(BoundingBox other)
        {
            MinPoint.X = Math.Min(MinPoint.X, other.MinPoint.X);
            MinPoint.Y = Math.Min(MinPoint.Y, other.MinPoint.Y);
            MinPoint.Z = Math.Min(MinPoint.Z, other.MinPoint.Z);

            MaxPoint.X = Math.Max(MaxPoint.X, other.MaxPoint.X);
            MaxPoint.Y = Math.Max(MaxPoint.Y, other.MaxPoint.Y);
            MaxPoint.Z = Math.Max(MaxPoint.Z, other.MaxPoint.Z);
        }
    }
}
